home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / Jooky / d2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-01  |  3.3 KB  |  176 lines

  1. #include "defines.h"
  2. #include "includes.h"
  3. #include "funcs.h"
  4.  
  5. void showit(char *string) {
  6.     FILE *display;
  7. #ifdef DEBUG
  8.     printf ("in showit %s\n",string);fflush(stdout);
  9. #endif
  10.     display=fopen(FUTABASERIAL,"w");
  11.     fprintf (display, "%s", string);
  12.     fclose (display);
  13.     return;
  14. }
  15.  
  16. void specialeffect(int effect) {
  17.     int x;
  18.     int y;
  19. #ifdef DEBUG
  20.     printf ("in specialeffect\n");fflush(stdout);
  21. #endif
  22.     for (x=1;x<=1;++x) {
  23.         for (y=1;y<=32;++y) showit ("\177");
  24.         for (y=1;y<=32;++y) showit ("\040"); 
  25.     }
  26.     return;
  27. }
  28.  
  29. int putline(char *inputline, char *position, int direction, char *slot) {
  30.     int length;
  31.     char *end;
  32.     char *displayline;
  33. #ifdef DEBUG
  34.     printf ("in putline\n");fflush(stdout);
  35. #endif
  36.  
  37.     displayline=malloc(17);
  38.     memset(displayline,0,17);
  39.  
  40.     length=strlen(inputline);
  41.     end=inputline+length;
  42.     showit("\002");
  43.     showit(slot);
  44.     strncpy(displayline,position,16);
  45.     showit(displayline);
  46.     fflush(stdout);
  47.     if ( 
  48.         ( ((end-position)<=16) && direction==1) 
  49.                 ||
  50.         ( (position<=inputline) && direction==0)
  51.     ) return (-1);
  52.     return (0);
  53. }
  54.  
  55. int stringpad(char *destination, char *source){
  56.     int retval;
  57.  
  58.     retval=0;
  59.  
  60.     memset(destination,0,1024);
  61.         if (strlen(source) < 16) {
  62.             strncpy(destination,"                ",16-strlen(source));
  63.             strncat(destination,source,strlen(source));
  64.             strncat(destination,"                ",16-strlen(source));
  65.             retval=0;
  66.         } else
  67.         if (strlen(source) >= 16) {
  68.             strncpy (destination,source,strlen(source));
  69.             retval=0;
  70.         } else
  71.         if (strlen(source) == 16) {
  72.             retval=-1;
  73.         }
  74.         return (retval);
  75. }
  76.  
  77. char *wheretostart(char *pointer,int direction){
  78.         if (direction==-1) return(pointer);
  79.         else return(pointer+1);
  80. }
  81.  
  82. void futaba(char *songname, int secint)
  83. {
  84.  
  85.     time_t timey;
  86.     time_t prevtime;
  87.  
  88.     char *toppos;
  89.     char *botpos;
  90.  
  91.     char *timerem;
  92.  
  93.     char *topline;
  94.     char *botline;
  95.     char *seconds;
  96.  
  97.     int topdir;
  98.     int botdir;
  99.     int topskip=0;
  100. /*    int botskip=0; */
  101.  
  102.     long minute;
  103.     long hour;
  104.     long second;
  105.     long secrem;
  106.  
  107.     secrem=(long)secint;
  108.  
  109.     seconds=calloc(1,10);
  110.  
  111.     timerem=calloc(1,80);
  112.  
  113.     topline=calloc(1,1024);
  114.     botline=calloc(1,1024);
  115.  
  116.     time(&timey);
  117.     prevtime=0;
  118.  
  119.     memset(timerem,0,80);
  120.     memset(topline,0,1024);
  121.     memset(botline,0,1024);
  122.  
  123.  
  124.     botdir=stringpad(botline,songname);
  125.     botpos=wheretostart(botline,botdir);
  126.  
  127.     for (secrem=(long)secint;secrem>0;)
  128.     {
  129.         time(&timey);
  130.         if (prevtime!=timey)
  131.         {
  132.             prevtime = timey ;
  133.             --secrem ;
  134.             hour   = secrem / 3600 ;
  135.             minute = secrem / 60 ;
  136.             second = secrem % 60 ;
  137.  
  138.             sprintf (timerem,"Remain: %.2ld:%.2ld:%.2ld",hour,minute,second);
  139.             topskip=0;
  140.         }
  141.         topdir=stringpad(topline,timerem);
  142.         toppos=wheretostart(topline,topdir);
  143.  
  144.     /*    usleep (10000);  */
  145.         if (topskip==0) {
  146.             if (topdir==1) {
  147.                 if (putline(topline,++toppos,topdir,"\001")==-1) {
  148.                     topdir=1-topdir;
  149.                 }
  150.             } else if (topdir==0) {
  151.                 if (putline(topline,--toppos,topdir,"\001")==-1) {
  152.                     topdir=1-topdir;
  153.                 }
  154.             }
  155.             if (topdir==-1) {
  156.                 putline(topline,toppos,-1,"\001");
  157.             }
  158.         }
  159.         topskip=1;
  160.  
  161.         if (botdir==1) {
  162.             if (putline(botline,++botpos,botdir,"\021")==-1)
  163.                 botdir=1-botdir;
  164.         } else if (botdir==0) {
  165.             if (putline(botline,--botpos,botdir,"\021")==-1)
  166.                 botdir=1-botdir;
  167.         }
  168.         if (botdir==-1) {
  169.             putline(botline,botpos,botdir,"\021");
  170.         }
  171.         usleep(50000);
  172.     }
  173.     specialeffect(0);
  174. };
  175.  
  176.